//
//  FBCache.h
// This is a totally generic implementation of NSURLCache which provides a 
// really simple on-disk cache for use on the iPhone, where the disk cache is 
// disabled
// 
//
//  Created by Alec Flett on 11/30/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface FBCache : NSURLCache {
    NSString* _cachePath;
    BOOL _disableDiskCache;
}

- (id)initWithMemoryCapacity:(NSUInteger)memoryCapacity diskCapacity:(NSUInteger)diskCapacity diskPath:(NSString *)path;

- (NSData*)dataForURL:(NSString*)URL;
- (NSData*)dataForURL:(NSString*)URL expires:(NSTimeInterval)expirationAge
            timestamp:(NSDate**)timestamp;
- (void)storeData:(NSData*)data forURL:(NSString*)URL;

// helper routine to allow synchronous fetching of images, for UITableViews

- (UIImage*)imageForURL:(NSString*)url;

// metadata for each URL - basically a dictionary of 
// NSCachedURLResponse length and mimetype
- (NSDictionary*)metadataForURL:(NSString*)URL;
- (void)storeMetadataForURL:(NSString*)URL data:(NSDictionary*)info;

// private
- (void)initCacheDirectory:(NSString*)dataPath;
- (NSData*)dataForKey:(NSString*)key expires:(NSTimeInterval)expirationAge
            timestamp:(NSDate**)timestamp;

- (void)storeData:(NSData*)data forKey:(NSString*)key;
- (NSString*)cachePathForKey:(NSString*)key;
- (NSString*)cachePathForURL:(NSString*)URL;
@end
